/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DickYang
 * Date: 2023-06-01
 * Time: 17:10
 *
 * 使用StringBuilder拼接字符串
 */
public class TestStringBuilder {
    public static void main(String[] args) {
        StringBuilder stringBuilder = new StringBuilder("hello");
        long start = System.currentTimeMillis();
        for (int i = 0; i < 10000; i++) {
            stringBuilder.append("word");
        }
        long end = System.currentTimeMillis();
        System.out.println(end - start);
    }
    public static void main4(String[] args) {
        StringBuilder stringBuilder = new StringBuilder("hello");
        stringBuilder.append("word").append(12);
        stringBuilder.append(10.89);
        System.out.println(stringBuilder.toString());
    }
    public static void main3(String[] args) {
        String str = "abc";
        long start = System.currentTimeMillis();
        for (int i = 0; i < 10000; i++) {
            str += "def";
        }
        long end = System.currentTimeMillis();
        System.out.println(end - start);
    }
    public static void main2(String[] args) {
        String str1 = "hello";
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(str1);
        stringBuilder.append("word");
        str1 = stringBuilder.toString();
        System.out.println(str1);
    }
    public static void main1(String[] args) {
        String str1 = "hello";
        str1 += "word";
        System.out.println(str1);
    }
} 
